﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserMasterForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.SystemManage.UserMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>用户管理</title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table>
            <tr>
                <td style="width: 100px;" align="right">
                    登录账号：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="aLoginCode" class="mini-textbox" emptytext="请输入登录账号" style="width: 150px;"
                        onenter="onKeyEnter" />
                </td>
                <td style="width: 100px;" align="right">
                    职员姓名：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="FullName" class="mini-textbox" emptytext="请输入姓名" style="width: 150px;"
                        onenter="onKeyEnter" />
                </td>
                <td style="width: 100px;" align="right">
                    手机号码：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="MobileNo" class="mini-textbox" emptytext="请输入手机号码" style="width: 150px;"
                        onenter="onKeyEnter" />
                </td>
                <td style="width: 100px">
                    <a class="mini-button" iconcls="icon-search" onclick="search()">查 询</a>
                </td>
            </tr>
            <tr>
                <td style="width: 100px;" align="right">
                    角色：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="Role" class="mini-combobox" style="width: 150px;" textfield="RoleName"
                        valuefield="RoleID" shownullitem="true" allowinput="true" />
                </td>
                <td style="width: 100px;" align="right">
                    部门：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="Dept" class="mini-combobox" style="width: 150px;" textfield="DptName"
                        valuefield="DptID" shownullitem="true" allowinput="false" />
                </td>
                <td style="width: 100px;" align="right">
                    状态：
                </td>
                <td style="width: 150px;" align="left">
                    <input id="RecStatus" name="RecStatus" shownullitem="true" allowinput="true" style="width: 150px;"
                        class="mini-combobox" textfield="text" valuefield="id" data="RecStatusData" />
                </td>
                <td style="width: 100px">
                    <a class="mini-button" iconcls="icon-reset" onclick="reset()">重 置</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a> <a
                        class="mini-button" iconcls="icon-edit" onclick="edit()" plain="true">编辑</a>
                    <a class="mini-button" iconcls="icon-modifypwd" onclick="editpwd()" plain="true">修改密码</a>
                    <span class="separator"></span><a class="mini-button" iconcls="icon-lock" onclick="lock()"
                        plain="true">锁定</a> <a class="mini-button" iconcls="icon-unlock" onclick="unlock()"
                            plain="true">解锁</a> <span class="separator"></span><a class="mini-button" iconcls="icon-excel"
                                onclick="ExportExcel();" plain="true">导出Excel</a> <span class="separator">
                    </span><a class="mini-button" onclick="close()" iconcls="icon-close" plain="true">关闭</a>
                </td>
            </tr>
        </table>
    </div>
    <!--撑满页面-->
    <div class="mini-fit">
        <div id="DataGridUsers" class="mini-datagrid" style="width: 100%; height: 100%;"
            idfield="UserID" sizelist="[10,20,50,100]" pagesize="20" onrowdblclick="ondoubleclick()">
            <div property="columns">
                <div type="indexcolumn">
                </div>
                <div field="RecStatus" width="50" headeralign="center" allowsort="true" renderer="onRecStatusRenderer">
                    状态
                </div>
                <div field="LoginCode" width="120" headeralign="center" allowsort="true">
                    登录账号
                </div>
                <div field="FullName" width="120" headeralign="center" allowsort="true">
                    职员姓名
                </div>
                <div field="MobileNo" width="100" headeralign="center" allowsort="true">
                    手机号码
                </div>
                <div field="RoleName" width="100" headeralign="center" allowsort="true">
                    角色
                </div>
                <div field="DptName" width="100" headeralign="center" allowsort="true">
                    部门
                </div>
                <div field="Desc" width="180" headeralign="center" allowsort="false">
                    描述
                </div>
            </div>
        </div>
    </div>
    <iframe id="exportIFrame" style="display: none;"></iframe>
    <script type="text/javascript">
        var RecStatusData = [{ id: 0, text: '已锁定' }, { id: 1, text: '未锁定'}];
        mini.parse();
        var role = mini.get("Role");
        var dept = mini.get("Dept");
        var grid = mini.get("DataGridUsers");
        role.setUrl("../Service/PublicHandler.ashx?action=GetRoleList");
        dept.setUrl("../Service/PublicHandler.ashx?action=GetDeptList");
        grid.setUrl("../Service/SystemManageHandler.ashx?action=GetUserList");
        grid.load();
        function add() {
            mini.open({
                url: "SystemManage/AddUserInfoForm.aspx",
                title: "新增用户", width: 420, height: 408,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
        function ondoubleclick() {
            edit();
        }
        function edit() {
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "SystemManage/EditUserInfoForm.aspx",
                    title: "编辑用户", width: 420, height: 408,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", UserID: row.UserID };
                        iframe.contentWindow.SetData(data);

                    },
                    ondestroy: function (action) {
                        grid.reload();

                    }
                });

            } else {
                mini.alert("请选中一条记录!");
            }
        }

        function editpwd() {
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "CommForm/ChangePasswordForm.aspx",
                    title: "修改密码", width: 290, height: 180,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "modify", UserID: row.UserID, LoginCode: row.LoginCode, FullName: row.FullName };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                    }
                });

            } else {
                mini.alert("请选中一条记录!");
            }
        }

        function lock() {
            var rows = grid.getSelected();
            if (rows) {
                if (rows.RecStatus == true) {
                    mini.confirm("您确定锁定:" + rows.LoginCode + "？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: "../service/SystemManageHandler.ashx?action=LockUser&UserID=" + rows.UserID,
                                success: function (text) {
                                    grid.reload();
                                },
                                error: function () {
                                }
                            });
                        } else {
                            return false;
                        }
                    });
                }
                else {
                    mini.alert(rows.LoginCode + " 当前状态已经是：锁定!");
                }

            } else {
                mini.alert("请选中一条您需要锁定的记录!");
            }
        }

        function unlock() {
            var rows = grid.getSelected();
            if (rows) {
                if (rows.RecStatus == false) {
                    mini.confirm("您确定解锁:" + rows.LoginCode + "？", "确定？",
                    function (action) {
                        if (action == "ok") {

                            $.ajax({
                                url: "../service/SystemManageHandler.ashx?action=UnlockUser&UserID=" + rows.UserID,
                                success: function (text) {
                                    grid.reload();
                                },
                                error: function () {
                                }
                            });
                        } else {
                            return false;
                        }
                    });
                }
                else {
                    mini.alert(rows.LoginCode + " 当前状态已经是：未锁定!");
                }

            } else {
                mini.alert("请选中一条您需要解锁的记录!");
            }
        }

        function search() {
            var aLoginCode = mini.get("aLoginCode").getValue();
            var fullName = mini.get("FullName").getValue();
            var MobileNo = mini.get("MobileNo").getValue();
            var roleID = mini.get("Role").getValue();
            var dptID = mini.get("Dept").getValue();
            var recStatus = mini.get("RecStatus").getValue();
            grid.load({ aLoginCode: aLoginCode, FullName: fullName, MobileNo: MobileNo, RoleID: roleID, DptID: dptID, RecStatus: recStatus });
        }
        function onKeyEnter(e) {
            search();
        }
        function ExportExcel() {
            var aLoginCode = mini.get("aLoginCode").getValue();
            var fullName = mini.get("FullName").getValue();
            var MobileNo = mini.get("MobileNo").getValue();
            var roleID = mini.get("Role").getValue();
            var dptID = mini.get("Dept").getValue();
            var recStatus = mini.get("RecStatus").getValue();
            var url = "../Service/SystemManageHandler.ashx?action=ExportUser&aLoginCode=" + aLoginCode + "&FullName=" + fullName + "&MobileNo=" + MobileNo + "&RoleID=" + roleID + "&DptID=" + dptID + "&RecStatus=" + recStatus;
            var exportIFrame = document.getElementById("exportIFrame");
            exportIFrame.src = url;
        }

        function reset(e) {
            mini.get("aLoginCode").setValue("");
            mini.get("FullName").setValue("");
            mini.get("MobileNo").setValue("");
            mini.get("Role").setValue("");
            mini.get("Dept").setValue("");
            mini.get("RecStatus").setValue("");
        }

        function onRecStatusRenderer(e) {
            if (e.value == "0") { return "<span style=\"color: Red;font-weight:bold;\">已锁定</span>"; }
            else if (e.value == "1") { return "<span style=\"color: Green;font-weight:bold;\">未锁定</span>"; }
            else { return ""; }
        }

        function CloseWindow(action) {
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function close() {
            CloseWindow("close");
        }
    </script>
</body>
</html>
